package net.oschina.app.fragment.center_message;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;

import com.chanven.lib.cptr.recyclerview.RecyclerAdapterWithHF;

import net.oschina.app.adapter.MeFollowRvAdapter;
import net.oschina.app.base.BaseAdapter;
import net.oschina.app.base.BaseFragment;
import net.oschina.app.bean.AttentionBean;
import net.oschina.app.bean.FriendBean;
import net.oschina.app.interf.FragmentType;
import net.oschina.app.protocol.me_follow.FollowProtocol;
import net.oschina.app.ui.DetailFragmentActivity;
import net.oschina.app.util.CommonUtils;

import java.util.List;

/**
 * Created by wei03 on 2017/1/14.
 */
public class FansFragment extends BaseFragment {
    private MeFollowRvAdapter mMeFollowRvAdapter;
    private List<FriendBean> mFriendBeen;

    @Override
    protected void OnSubItemClick(RecyclerAdapterWithHF adapter, RecyclerView.ViewHolder vh, int position) {
        Intent intent = new Intent(CommonUtils.getContext(), DetailFragmentActivity.class);
        intent.putExtra(FragmentType.FRAGMENT_TYPE, FragmentType.TYPE_ME_NEWMESSAGE_DETAIL);
        String friendname = mFriendBeen.get(position).getName();
        intent.putExtra("title", friendname);
        startActivity(intent);
    }

    @Override
    protected BaseAdapter getRvAdapter() {
        mMeFollowRvAdapter = new MeFollowRvAdapter();
        return mMeFollowRvAdapter;
    }

    @Override
    protected int onLoadSubData() {
        Bundle arguments = getArguments();
        String relation = "";
        if (arguments != null) {
            relation = arguments.getString("relation");
        }
        FollowProtocol fans = new FollowProtocol(relation);
        final AttentionBean following = fans.getData(mList.size());
        if (following != null) {
            CommonUtils.runOnMainThread(new Runnable() {
                @Override
                public void run() {
                    mFriendBeen = following.getFriends();
                    mMeFollowRvAdapter.setDatas(mFriendBeen);
                }
            });
            return STATE_SUCCESS;
        }
        return STATE_EMPTY;
    }
}
